package cn.zs.supply.common.core.aspect;

import cn.zs.supply.common.core.security.simple.FunctionImp;
import cn.zs.supply.common.core.security.simple.Use;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Aspect
@Component
@ComponentScan(basePackages="cn.zs.supply.common.core.security.simple")
public class UseAspect {

    @Autowired
    private FunctionImp factory;

    @Pointcut("@annotation(cn.zs.supply.common.annotation.UserAnnotation)")
    public void operationLog(){}


    @Around("operationLog()")
    public Object  doAround(ProceedingJoinPoint joinPoint) throws Throwable{
        Object[] args = joinPoint.getArgs();
        Use args0 = (Use)args[0];
        Object object=factory.serviceUse(args0);
        args[0] = object;
        Object retVal = joinPoint.proceed(args);
        return retVal;
    }

    /**
     * 进入业务方法前
     * */
    @Before("operationLog()")
    public void doBeforeAdvice(JoinPoint joinPoint){
        //System.out.println("进入方法前执行.....");
    }



    public void onApplicationEvent(ContextRefreshedEvent event) {
        // 根容器为Spring容器
        if(event.getApplicationContext().getParent()==null){

            }
            System.err.println("=====onApplicationEvent====="+event.getSource().getClass().getName());
        }






}
